#ifndef __PINFLOW_MANAGER_H__
#define __PINFLOW_MANAGER_H__

#include "thread_safe_list.h"
#include "task.h"
#include "machine.h"
#include "config.h"

#include <string>
#include <map>
#include <vector>

namespace pinflow
{

class Manager
{
public:
    static Manager& Instance() {
        static Manager instance;
        return instance;
    }
    ~Manager() {}

    TaskBase::sptr CreateTask(const std::string& name,
        const Config& config);
    Machine::sptr CreateMachine(const std::string& name,
        const Config& config);
    // 创建线程安全队列
    bool Prepare(const Config& config);

    // 分发task给Worker
    bool Deploy();
    
    // 主Loop循环
    bool Loop(bool& flag);

private:
    Manager() {}
    // 线程安全队列
    std::map<std::string, ThreadSafeList<InOutBase::sptr>::sptr> queues_;
    std::map<std::string, TaskBase::sptr> queue_map_;
    std::vector<Machine::sptr> machines_;
}; // class Manager

} // namespace pinflow

#endif  // __PINFLOW_MANAGER_H__